package com.person.jiaiplan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.person.jiaiplan.assembler.ScheduleSettingAssembler;
import com.person.jiaiplan.mapper.ScheduleLogsMapper;
import com.person.jiaiplan.pojo.dto.AddPlanInfoReqDTO;
import com.person.jiaiplan.pojo.dto.PlanInfoResDTO;
import com.person.jiaiplan.pojo.entity.ScheduleLogs;
import com.person.jiaiplan.pojo.signle.SignleSnowFlake;
import com.person.jiaiplan.service.ScheduleLogsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class ScheduleLogsServiceImpl extends ServiceImpl<ScheduleLogsMapper, ScheduleLogs> implements ScheduleLogsService {


    @Override
    public Boolean addPlan(AddPlanInfoReqDTO addPlanInfoReqDTO) {

        ScheduleLogs scheduleLogs = ScheduleSettingAssembler.INSTANCE.toScheduleLogs(addPlanInfoReqDTO);
        scheduleLogs.setId(SignleSnowFlake.getSnowflakeId());
        scheduleLogs.setCreateTime(new Date());
        // 新增的默认为进行中
        scheduleLogs.setPlanStatus(1);
        return this.baseMapper.insert(scheduleLogs) > 0;
    }

    @Override
    public Boolean deletePlan(Long id) {

        // 删除的时候同时需要删除关联的周期明细数据
        return this.baseMapper.deleteById(id) > 0;
    }

    @Override
    public PlanInfoResDTO updatePlanInfo(PlanInfoResDTO planInfoResDTO) {
        return this.baseMapper.updateById(ScheduleSettingAssembler.INSTANCE.toScheduleLogs(planInfoResDTO)) > 0 ? planInfoResDTO : null;
    }
}
